function [ ret ] = feed_forward( weights, pattern, S )
%FEED_FORWARD Summary of this function goes here
%   Detailed explanation goes here

global LAYERS;

deltas = cell(1,length(LAYERS));
h = cell(1,length(LAYERS));
input = pattern;
for i = 1:length(LAYERS)
    hi = weights{i} * input;
    h{i} = hi;
    input = vertcat(-1, g_function(hi));
end
o = input(2,:);

deltas{1} = g_function_p(o) * (S - o);

ret{1} = deltas;
ret{2} = h;
ret{3} = o;

end

